<!-- 加工检验自动查询 -->
<template>
  <div>
    <div style="margin-bottom: 10px;">
      <el-row style="margin: 0 0 5px 0;text-align: center;background-color: #DCDFE6;">
        <el-input v-model="countdown" style="width: 190px;">
          <template slot="prepend">还有</template>
          <template slot="append">秒刷新</template>
        </el-input>
      </el-row>
    </div>

    <div class="avue-crud">
      <el-table :data="dataList" border v-loading="dataListLoading" :max-height="tableHeight">
        <el-table-column prop="saleBillId" label="配镜单号">
          <template slot-scope="scope">
            <el-button type="text" @click="checkDetailByOrder(scope.row.saleBillId)">{{scope.row.saleBillId}}</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="customerName" label="顾客姓名"></el-table-column>
        <el-table-column prop="createTime" label="配镜日期"></el-table-column>
        <el-table-column prop="takeMirroTime" label="取镜时间"></el-table-column>
        <el-table-column prop="deptName" label="配镜门店"></el-table-column>
        <el-table-column prop="sendMaterialTime" label="发料日期"></el-table-column>
        <el-table-column label="操作" fixed="right">
          <template slot-scope="scope">
            <el-button v-if="permissions.eims_workcheck_add" type="text" icon="el-icon-edit" @click="addInspect(scope.row.saleId)">加工</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <div class="avue-crud__pagination">
      <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex" :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage" background layout="total, sizes, prev, pager, next"></el-pagination>
    </div>
    <check-form v-if="checkFormVisible" ref="checkForm" @refreshDataList="getDataList"></check-form>
    <order-info v-if="infoVisible" ref="infoDialog"></order-info>
  </div>
</template>

<script>
  import { mapGetters } from "vuex"
  import { getObj } from '@/api/eims/worklink'
  import { workCheckFetchList } from "@/api/eims/formalInspect"
  import { getDeptInfoByDeptType, getDeptListByUnitId} from '@/api/admin/dept'

  import CheckForm from "./FormCheckAuto"
  import OrderInfo from '@/views/eims/optician/glassesinfo/detail'

  export default {
    props: ['tableHeight'],
    data() {
      return {
        countdown: '',
        isKeep: true,
        dataForm: {},
        dataList: [],
        deptOptions: [],
        deptIds: [],
        pageIndex: 1,
        pageSize: 100,
        totalPage: 0,
        dataListLoading: false,
        addOrUpdateVisible: false,
        checkFormVisible: false,
        infoVisible: false,
        unitId: '',
        deptType: '',
        searchForm: {
          saleId: "",
          customerName: "",
          deptId: ""
        }
      };
    },
    computed: {
      ...mapGetters(["permissions", "userInfo"])
    },
    components: {
      CheckForm,
      OrderInfo
    },
    methods: {
      //
      init(){
        clearInterval(this.setIn)
        this.getDataList()
        this.countdown = 10
        // this.isKeep = true
        this.countDown()
      },
      //  查询数据
      searchHandle() {
        this.pageIndex = 1
        this.getDataList()
      },
      // 清空搜索框
      clearDataForm() {
        this.dataForm = {};
      },
      // 获取数据列表
      getDataList() {
        this.dataListLoading = true;
        this.dataForm.workDeptId = this.userInfo.lessDeptId
        let params = {
          current: this.pageIndex,
          size: this.pageSize
        };
        workCheckFetchList(Object.assign(params, this.dataForm)).then(response => {
          if(response.data.code == '0'){
            this.dataList = response.data.data.records
            this.totalPage = response.data.data.total
          }else{
            this.$message.error(response.data.msg)
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle(val) {
        this.pageSize = val;
        this.pageIndex = 1;
        this.getDataList();
      },
      // 当前页
      currentChangeHandle(val) {
        this.pageIndex = val;
        this.getDataList();
      },
      // 加工按钮
      addInspect(saleId) {
        this.checkFormVisible = true;
        this.$nextTick(() => {
          this.$refs.checkForm.init(saleId)
        })
      },
      //  查看配镜单详情
      checkDetailByOrder(order) {
        this.infoVisible = true;
        this.$nextTick(() => {
          this.$refs.infoDialog.init('', order, '配镜单详情');
        });
      },
      //  倒计时，定时刷新
      countDown() {
        if(this.isKeep){
          if(this.countdown > 0 ){
            this.countdown -= 1
            this.setIn = setTimeout(() => {
              this.countDown()
            },1000)
          }else{
            this.getDataList()
            setTimeout(() => {
              this.countdown = 10
              this.countDown()
            },1000)
          }
        }
      },
    }
  };
</script>
